/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entitys.Users;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import utils.DBUtils;

/**
 * 用户类的数据库操作类
 * @author Administrator
 */
public class UsersDAO {
    public Users queryUsersByLogin( String name, String pwd ) {
        Users user = null;
        String sql = "select usersid from usersinfo where usersname=? and userspwd=?";
        Connection conn = DBUtils.getConnection();
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(sql);
            pst.setString(1, name);
            pst.setString(2, pwd);
            ResultSet rs = pst.executeQuery();
            if ( rs.next() ) {
                user = new Users();
                user.setId(rs.getInt(1));
                user.setName(name);
            }
        } catch (SQLException ex) {
            Logger.getLogger(UsersDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return user;
    }
}
